package mosync.mobilelualiveditor.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

public class Widget extends JFrame
{
	private static final long serialVersionUID = 1L;

	public JComponent createTopContent()
	{
		JPanel main = new JPanel(new BorderLayout());
		main.setBackground((Color.RED));

		/* -------- Toolbar ---------- */
		JPanel toolbar = new JPanel();
		toolbar.setBackground(Color.YELLOW);
		toolbar.setMinimumSize(new Dimension(100, 300));
		toolbar.setBounds(0, 0, 800, 100);

		String[] labels = { "Screen", "VerticalLayout", "Button" };
		final JComboBox widgetCombo = new JComboBox(labels);
		toolbar.add(widgetCombo);
		final JButton createWidgetButton = new JButton("Add widget");
		toolbar.add(createWidgetButton);
		final JButton loadXMLButton = new JButton("Load XML...");
		toolbar.add(loadXMLButton);
		final JButton saveXMLButton = new JButton("Save XML...");
		toolbar.add(saveXMLButton);
		final JButton cppButton = new JButton("Cpp");
		toolbar.add(cppButton);
		final JButton luaButton = new JButton("Lua");
		toolbar.add(luaButton);
		main.add(toolbar, BorderLayout.PAGE_START);

		/* -------- Widget Tree ---------- */
		DefaultMutableTreeNode treeTop = new DefaultMutableTreeNode("UI");
		JTree tree = new JTree(treeTop);
		JScrollPane treeScrollView = new JScrollPane(tree);
		treeScrollView.setBackground(Color.GREEN);
		main.add(treeScrollView, BorderLayout.CENTER);
		main.setMinimumSize(new Dimension(100, 50));

		/* -------- Bottom toolbar ---------- */
		JPanel toolbarBottom = new JPanel();
		toolbarBottom.setBackground(Color.YELLOW);
		toolbarBottom.setMinimumSize(new Dimension(100, 300));
		toolbarBottom.setBounds(0, 0, 800, 100);

		final JLabel nameLabel = new JLabel("Widget name:");
		final JTextField nameEdit = new JTextField();
		nameEdit.setColumns(10);

		toolbarBottom.add(nameLabel);
		toolbarBottom.add(nameEdit);
		final JButton renameButton = new JButton("Rename");
		toolbarBottom.add(renameButton);
		final JButton removeButton = new JButton("Remove");
		toolbarBottom.add(removeButton);
		main.add(toolbarBottom, BorderLayout.PAGE_END);

		return main;
	}

	public JComponent createBottomContent()
	{
		JPanel bottomContent = new JPanel(new BorderLayout());
		bottomContent.setBackground(Color.RED);
		Dimension minimumSize = new Dimension(100, 50);
		bottomContent.setMinimumSize(minimumSize);

		return bottomContent;
	}

	public JComponent createWidgetEditorUI()
	{
		JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
			createTopContent(), createBottomContent());
		splitPane.setOneTouchExpandable(true);
		splitPane.setDividerLocation(300);
		return splitPane;
	}

	public Widget()
	{
		System.out.println("Helloues");
		this.setSize(800, 600);
		this.setLocation(50, 50);
		this.getContentPane().add(createWidgetEditorUI());
		this.setVisible(true);

	}

	public static void main(String[] args)
	{
		new Widget();
	}
}